import request from '@/utils/request'

// -----进货单----
export function getPurchase(data) {
  return request({
    url: '/po/purchase/getResPageData',
    method: 'post',
    data
  })
}

export function getPurchaseById(id) {
  return request({
    url: '/po/purchase/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function savePurchase(data) {
  return request({
    url: '/po/purchase/save',
    method: 'post',
    data
  })
}

export function delPurchase(id, billDate) {
  return request({
    url: '/po/purchase/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditPurchase(data) {
  return request({
    url: '/po/purchase/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildPurchaseEntry(data) {
  return request({
    url: '/po/purchase/buildWarehousingEntryByHeaderId',
    method: 'post',
    data: data
  })
}

export function buildVoucherByHeaderId(data) {
  return request({
    url: '/po/purchase/buildVoucherByHeaderId',
    method: 'post',
    data: data
  })
}

export function printByHeaderId(url, id, billDate) {
  return request({
    url: url + '/printByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

// -----------采购退货----------

export function getPurchaseReturned(data) {
  return request({
    url: '/po/purchaseReturned/getResPageData',
    method: 'post',
    data
  })
}

export function getPurchaseReturnedById(id) {
  return request({
    url: '/po/purchaseReturned/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function savePurchaseReturned(data) {
  return request({
    url: '/po/purchaseReturned/save',
    method: 'post',
    data
  })
}

export function delPurchaseReturned(id, billDate) {
  return request({
    url: '/po/purchaseReturned/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditPurchaseReturned(data) {
  return request({
    url: '/po/purchaseReturned/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildPurchaseReturnedEntry(data) {
  return request({
    url: '/po/purchaseReturned/buildWarehousingEntryReturnedByHeaderId',
    method: 'post',
    data: data
  })
}

export function buildVoucherReturnedByHeaderId(data) {
  return request({
    url: '/po/purchaseReturned/buildVoucherByHeaderId',
    method: 'post',
    data: data
  })
}

// -----------------------------入库单----------------------------

export function getWarehousing(data) {
  return request({
    url: '/ic/warehousingEntry/getResPageData',
    method: 'post',
    data
  })
}

export function getWarehousingById(id) {
  return request({
    url: '/ic/warehousingEntry/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveWarehousing(data) {
  return request({
    url: '/ic/warehousingEntry/save',
    method: 'post',
    data
  })
}

export function delWarehousing(id, billDate) {
  return request({
    url: '/ic/warehousingEntry/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditWarehousing(data) {
  return request({
    url: '/ic/warehousingEntry/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildWarehousingEntry(data) {
  return request({
    url: '/ic/warehousingEntry/buildPurchaseByHeaderId',
    method: 'post',
    data
  })
}

// ------------销售退货出库-------------

export function getWarehousingReturned(data) {
  return request({
    url: '/ic/warehousingEntryReturned/getResPageData',
    method: 'post',
    data
  })
}

export function getWarehousingReturnedById(id) {
  return request({
    url: '/ic/warehousingEntryReturned/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveWarehousingReturned(data) {
  return request({
    url: '/ic/warehousingEntryReturned/save',
    method: 'post',
    data
  })
}

export function delWarehousingReturned(id, billDate) {
  return request({
    url: '/ic/warehousingEntryReturned/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditWarehousingReturned(data) {
  return request({
    url: '/ic/warehousingEntryReturned/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildWarehousingEntryReturned(data) {
  return request({
    url: '/ic/warehousingEntryReturned/buildPurchaseReturnedByHeaderId',
    method: 'post',
    data
  })
}

// -----出库单----
export function getOutboundOrder(data) {
  return request({
    url: '/ic/outboundOrder/getResPageData',
    method: 'post',
    data
  })
}

export function getOutboundOrderById(data) {
  return request({
    url: '/ic/outboundOrder/getByHeaderId',
    method: 'post',
    data
  })
}

export function saveOutboundOrder(data) {
  return request({
    url: '/ic/outboundOrder/save',
    method: 'post',
    data
  })
}

export function delOutboundOrder(data) {
  return request({
    url: '/ic/outboundOrder/deleteByHeaderId',
    method: 'post',
    data
  })
}

export function auditOutboundOrder(data) {
  return request({
    url: '/ic/outboundOrder/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildOutboundOrder(data) {
  return request({
    url: '/ic/outboundOrder/buildSalesByHeaderId',
    method: 'post',
    data
  })
}

export function buildDeliveryByHeaderId(data) {
  return request({
    url: '/ic/outboundOrder/buildDeliveryByHeaderId',
    method: 'post',
    data
  })
}

// ------采购退货入库----
export function getOutboundOrderReturned(data) {
  return request({
    url: '/ic/outboundOrderReturned/getResPageData',
    method: 'post',
    data
  })
}

export function getOutboundOrderReturnedById(id) {
  return request({
    url: '/ic/outboundOrderReturned/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveOutboundOrderReturned(data) {
  return request({
    url: '/ic/outboundOrderReturned/save',
    method: 'post',
    data
  })
}

export function delOutboundOrderReturned(id, billDate) {
  return request({
    url: '/ic/outboundOrderReturned/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditOutboundOrderReturned(data) {
  return request({
    url: '/ic/outboundOrderReturned/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildOutboundOrderReturned(data) {
  return request({
    url: '/ic/outboundOrderReturned/buildSalesReturnedByHeaderId',
    method: 'post',
    data
  })
}

// 移库单
export function getMovement(data) {
  return request({
    url: '/ic/movement/getResPageData',
    method: 'post',
    data
  })
}

export function getMovementById(id) {
  return request({
    url: '/ic/movement/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveMovement(data) {
  return request({
    url: '/ic/movement/save',
    method: 'post',
    data
  })
}

export function delMovement(id, billDate) {
  return request({
    url: '/ic/movement/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditMovement(data) {
  return request({
    url: '/ic/movement/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildMovement(id) {
  return request({
    url: '/ic/movement/buildPurchaseByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function confirmMovement(data) {
  return request({
    url: '/ic/movement/confirmByHeaderId',
    method: 'post',
    data
  })
}

// -----调拨单----
export function getAllocation(data) {
  return request({
    url: '/ic/allocation/getResPageData',
    method: 'post',
    data
  })
}

export function getAllocationById(id) {
  return request({
    url: '/ic/allocation/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function saveAllocation(data) {
  return request({
    url: '/ic/allocation/save',
    method: 'post',
    data
  })
}

export function delAllocation(id, billDate) {
  return request({
    url: '/ic/allocation/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditAllocation(data) {
  return request({
    url: '/ic/allocation/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildAllocation(id) {
  return request({
    url: '/ic/allocation/buildPurchaseByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function confirmAllocation(data) {
  return request({
    url: '/ic/allocation/confirmByHeaderId',
    method: 'post',
    data
  })
}

// -----预收单----
export function getPresale(data) {
  return request({
    url: '/ps/presale/getResPageData',
    method: 'post',
    data
  })
}

export function getPresaleById(id) {
  return request({
    url: '/ps/presale/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function savePresale(data) {
  return request({
    url: '/ps/presale/save',
    method: 'post',
    data
  })
}

export function delPresale(id, billDate) {
  return request({
    url: '/ps/presale/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditPresale(data) {
  return request({
    url: '/ps/presale/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildPresaleVoucher(data) {
  return request({
    url: '/ps/presale/buildVoucherByHeaderId',
    method: 'post',
    data
  })
}
export function buildReturnedBill(id) {
  return request({
    url: '/ps/presale/buildReturnedByHeaderId',
    method: 'post',
    data: { id }
  })
}

// ---销售单获取商品价格
export function getItemPrice(data) {
  return request({
    url: '/bd/price/getPriceSVOByItemIdCustId',
    method: 'post',
    data
  })
}

// --------预收退款
export function getPresaleReturned(data) {
  return request({
    url: '/ps/presaleReturned/getResPageData',
    method: 'post',
    data
  })
}

export function getPresaleReturnedById(id) {
  return request({
    url: '/ps/presaleReturned/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function getBillReturnedByPresaleHeaderId(id) {
  return request({
    url: '/ps/presaleReturned/getByPresaleHeaderId',
    method: 'post',
    data: { id }
  })
}

export function savePresaleReturned(data) {
  return request({
    url: '/ps/presaleReturned/save',
    method: 'post',
    data
  })
}

export function delPresaleReturned(id, billDate) {
  return request({
    url: '/ps/presaleReturned/deleteByHeaderId',
    method: 'post',
    data: { id, billDate }
  })
}

export function auditPresaleReturned(data) {
  return request({
    url: '/ps/presaleReturned/auditByHeaderId',
    method: 'post',
    data
  })
}

export function buildPresaleReturnedVoucher(data) {
  return request({
    url: '/ps/presaleReturned/buildVoucherByHeaderId',
    method: 'post',
    data
  })
}

// ---------------------结算方式（6个）-----------------

export function queryPurchaseSettleType() {
  return request({
    url: '/po/purchase/getSettleTypeList',
    method: 'post'
  })
}

export function queryPurchaseReturnedSettleType() {
  return request({
    url: '/po/purchaseReturned/getSettleTypeList',
    method: 'post'
  })
}

export function querySalesSettleType() {
  return request({
    url: '/so/sales/getSettleTypeList',
    method: 'post'
  })
}

export function querySalesReturnedSettleType() {
  return request({
    url: '/so/salesReturned/getSettleTypeList',
    method: 'post'
  })
}

export function queryPresaleSettleType() {
  return request({
    url: '/ps/presale/getSettleTypeList',
    method: 'post'
  })
}

export function queryPresaleReturnedSettleType() {
  return request({
    url: '/ps/presaleReturned/getSettleTypeList',
    method: 'post'
  })
}

export function queryReceiptSettleType(data) {
  return request({
    url: '/rp/receiptPayment/getSettleTypeList',
    method: 'post',
    data
  })
}

// 获取带价格的商品列表
export function getResPageByFuzzyCustId(data) {
  return request({
    url: '/bd/price/getResPageByFuzzyCustId',
    method: 'post',
    data
  })
}

// 查看审核意见
export function getAuditInfoByHeaderId(id) {
  return request({
    url: '/log/auditInfo/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

// 查看确认意见
export function getConfirmInfoByHeaderId(id) {
  return request({
    url: '/log/confirmInfo/getByHeaderId',
    method: 'post',
    data: { id }
  })
}

export function printPDF(path, data) {
  return request({
    url: '/' + path + '/printPDF',
    method: 'post',
    data
  })
}

export function exportExcel(path, data) {
  const exportUrl = path + '/exportExcel'
  var temp = document.createElement('form')
  temp.action = exportUrl
  temp.method = 'POST'
  temp.style.display = 'none'
  for (var x in data.queryParam) {
    var opt = document.createElement('textarea')
    opt.name = x
    opt.value = data.queryParam[x] || null
    temp.appendChild(opt)
  }
  document.body.appendChild(temp)
  temp.submit()
  return temp
}

